// 发送评论或者删除评论
export let comment = {
  namespaced: true,
  state: {
    myComment: {},
    t: 1,
    commentId: "",
    placeholder: "说点什么吧，也许Ta都听的到"
  },
  actions: {
    getComment(store, data = {}) {
      let url = "/comment?t=" + data.t + "&type=" + data.type + "&id=" + data.id + "&content=" + data.content + "&commentId=" + data.commentId + "&timestamp=" + new Date().getTime();
      return new Promise((resolve, reject) => {
        axios.get(url).then(({
          data
        }) => {
          store.commit('setComment', data)
          resolve(data);
        }).catch((error) => {
          if (error.response) {
            reject(error.response.data)
          }
        });
      });
    },
  },
  mutations: {
    setComment(state, data) {
      state.myComment = data;
    },
    setT(state, data) {
      state.t = data;
    },
    setCommentId(state, data) {
      state.commentId = data;
    },
    setPlaceholder(state, data) {
      state.placeholder = data;
    },
  }
}
